{extend name="base"/}
{block name="main"}
<link rel="stylesheet" type="text/css" href="/public/css/defau.css">
<article class="cl pd-20">
	<div class="n_tab_line">
            <a href="{:url('config/send_sms')}" class="n_tab_list">短信通知</a>
            <div class="cl"></div>
        </div>
	<form action="" method="post" class="form form-horizontal" id="">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>是否开启:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="skin-minimal">
					<div class="radio-box" style="padding-left:0;">
						<input type="radio" value="2" {if condition="$info.status==2"} checked {/if} id="radio-1" name="status">
						<label for="radio-1">不开启</label>
					</div>
					<div class="radio-box">
						<input type="radio" value="1" {if condition="$info.status==1"} checked {/if} id="radio-2" name="status">
						<label for="radio-2">开启</label>
					</div>
				</div>
				<i><a href="https://help.aliyun.com/document_detail/55451.html?spm=a2c4g.11186623.6.572.379c3a76T2gaeo" target="_blank">参数获取请参照官网详情<span style="color: red">[请及时保存ID和Secret]</span></a></i>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>阿里云AccessKeyId :</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['ali_id']}" placeholder="阿里云AccessKeyId" class="input-text" id="ali_id">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>阿里云AccessKeySecret:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['ali_token']}" placeholder="阿里云AccessKeySecret" class="input-text" id="ali_token">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>阿里云短信签名 :</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['ali_name']}" placeholder="阿里云短信签名" class="input-text" id="ali_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>阿里云短信模板Id :</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['ali_code']}" placeholder="阿里云短信模板Id" class="input-text" id="ali_code"><br>
				<span>模板内容: 您有一个新的订单，订单号：${order}</span><br>
                <span style="color: red;">注意：目前只支持设置新订单通知,请不要修改变量字段</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>接收人电话:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['phone']}" class="input-text" placeholder="接收人电话,多个请用英文逗号隔开" id="phone">
			</div>
		</div>
        {if $info.ok_use>0}
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">已使用量:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$info['ok_use']}" class="input-text" disabled>
			</div>
		</div>
        {/if}
		<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
		<input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            <input type="hidden" id="id" value="{$info.id|default=''}">
		<input class="btn btn-primary radius" onclick="test_sms()" type="button" value="&nbsp;&nbsp;测试&nbsp;&nbsp;">
		</div>
		</div>
	</form>
</article>
{/block}
{block name="script"}
<script type="text/javascript">
	function addSuppAjax() {
	    var status=$("input[name=status]:checked").val(),
			ali_id=$("#ali_id").val(),
			ali_token=$("#ali_token").val(),
			ali_name=$("#ali_name").val(),
			ali_code=$("#ali_code").val(),
            phone=$("#phone").val(),
            id=$("#id").val();
		$.ajax({
			type:"post",
			data:{
			    status:status,
                ali_id:ali_id,
                ali_token:ali_token,
                ali_name:ali_name,
                ali_code:ali_code,
                phone:phone,
                id:id
			},
			url:"{:url('config/send_sms')}",
			success:function (res) {
				if(res["code"]>0){
                    layer.msg('保存成功',{icon:1,time:1000},function () {
                        window.location.reload();
                    });
				}else {
                    layer.msg('保存失败',{icon:2,time:1000});
				}
            }
		})
    }
    function test_sms() {
        var ali_id=$("#ali_id").val(),
            ali_token=$("#ali_token").val(),
            ali_name=$("#ali_name").val(),
            ali_code=$("#ali_code").val(),
            phone=$("#phone").val();
        layer.confirm("多个手机号将只发送第一个手机号,发送变量为ABCDEF",function () {
            $.ajax({
                type:"post",
                data:{
                    ali_id:ali_id,
                    ali_token:ali_token,
                    ali_name:ali_name,
                    ali_code:ali_code,
                    phone:phone
                },
                url:"{:url('config/test_sms')}",
                success:function (res) {
                    if(res["Code"]=="OK"){
                        layer.msg('已发送，请查收',{icon:1,time:1000});
                    }else {
                        layer.msg(res["Message"],{icon:2,time:1000});
                    }
                }
            })
        })
    }
</script>
{/block}